package editeurGraphiti.features;

import modeleProcessus.Processus;

import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.features.impl.AbstractAddFeature;
import org.eclipse.graphiti.mm.pictograms.Diagram;
import org.eclipse.graphiti.mm.pictograms.PictogramElement;

public class AddProcessusFeature extends AbstractAddFeature {

	public AddProcessusFeature(IFeatureProvider fp) {
		super(fp);
	}

	@Override
	public boolean canAdd(IAddContext context) {
		// check if user wants to add a Processus
		if (context.getNewObject() instanceof Processus) {
			// check if user wants to add to a diagram
			if (context.getTargetContainer() instanceof Diagram) {
				return true;
			}
		}
		return false;
	}

	@Override
	public PictogramElement add(IAddContext context) {
		Processus addedProcessus = (Processus) context.getNewObject();
		Diagram targetDiagram = (Diagram) context.getTargetContainer();

		// create link and wire it
		link(targetDiagram.getGraphicsAlgorithm().getPictogramElement(),
				addedProcessus);

		return null;

	}

}
